package com.ganee.agora.adapter

import android.text.TextUtils
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ganee.agora.R
import com.ganee.agora.manager.RecyclerViewHolder
import com.ganee.agora.model.HomeListBean
import com.ganee.baselib.widget.image.transform.GlideRoundTransform
import com.ganee.baselib.mvvmlibrary.widget.loadingdrawable.DensityUtil
import com.ganee.agora.manager.RoundedCornersTransform
import com.ganee.agora.model.InsertActivityEntity
import com.ganee.agora.model.SignUpEntity
import com.ganee.agora.model.TicketInfoEntity


/**
 *    @author : EricCui
 *    date   : 2020-01-01 17:52
 *    desc   : SignUp adapter
 */

class SignUpAdapter(entityList: MutableList<TicketInfoEntity>) : BaseQuickAdapter<TicketInfoEntity,
        RecyclerViewHolder>(R.layout.item_recyclerview_sign_up, entityList) {


    override fun convert(helper: RecyclerViewHolder, item: TicketInfoEntity) {
        if (item != null) {
            val icon = helper.getView<ImageView>(R.id.item_iv_qrcode) as ImageView
            Glide.with(mContext)
                    .load(item.ticketPic)
                    .transform(GlideRoundTransform(mContext))
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .placeholder(R.drawable.home_placeholder)
                    .error(R.drawable.home_placeholder)
                    .into(icon)

            helper.setText(R.id.item_tv_title, item.eventTitle)
            var startTime:String? = null
            if (!TextUtils.isEmpty(item.startTime)){
                startTime = getTime(item.startTime!!)
            } else {
                startTime = ""
            }
            var endTime:String? = null
            if (!TextUtils.isEmpty(item.endTime)){
                endTime = getTime(item.endTime!!)
            } else {
                endTime = ""
            }

            helper.setText(R.id.item_tv_time, "$startTime - $endTime")
                    .setText(R.id.item_tv_user, item.location)
        }
    }

    private fun getTime(time: String):String {

        if (TextUtils.isEmpty(time)) return ""
        var mMonth: String? = null

        var month = time.substring(4, 6).toInt()
        val day = time.substring(6, 8)
        val hour = time.substring(8, 10)
        val minute = time.substring(10, 12)

        when (month) {
            1 -> mMonth = "Jan"
            2 -> mMonth = "Feb"
            3 -> mMonth = "Mar"
            4 -> mMonth = "Apr"
            5 -> mMonth = "May"
            6 -> mMonth = "Jun"
            7 -> mMonth = "Jul"
            8 -> mMonth = "Aug"
            9 -> mMonth = "Sept"
            10 -> mMonth = "Oct"
            11 -> mMonth = "Nov"
            12 -> mMonth = "Dec"
        }

        var time: String = if (hour.toInt() >= 12) {
            hour + ":" + minute + "pm"
        } else {
            hour + ":" + minute + "am"
        }

        return "$mMonth $day,$time"
    }

}